<?php
namespace Mobile\Model;
use Think\Model\ViewModel;
class BlogViewModel extends ViewModel{
	public $viewFields = array(
		'Blog'=>array('id','title','time','type','description','author','cid','_type'=>'LEFT'),
		'Picture'=>array('id'=>'p_id','url','_on'=>'Blog.id=Picture.bid','_type'=>'LEFT'),
		'Category'=>array('id'=>'c_id','name'=>'c_name', '_on'=>'Blog.cid=Category.id','_type'=>'LEFT'),
		'Attr'=>array('id'=>'a_id','name'=>'a_name','color', '_on'=>'Blog.type=Attr.id')

		);

	public function indexBlogs($limit=5,$type=1,$del=0){
		$where = array('type'=>$type,'del'=>$del);
		$field = array('id','title','c_name','color','time','url','description','author','cid');
		return $this->field($field)->where($where)->limit($limit)->order('time DESC')->select();
	}
	public function listBlogs($cids,$limit,$del=0){
		$where = array('del'=>$del,'cid'=> array('IN',$cids));
		$field = array('id','title','color','time','description','cid','a_name');
		return $this->field($field)->where($where)->order('type DESC,time DESC')->limit($limit)->select();
	}
	public function searchBlogs($limit,$type,$content,$del=0){
		$where = array($type=>array('LIKE',"%".$content."%"),'del'=>$del);
		$field = array('id','title','c_name','color','time','url','description','author','cid','a_name');
		return $this->field($field)->where($where)->order('type DESC,time DESC')->limit($limit)->select();
	}
}